<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增任务')" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-mission-add">
        <div class="form-group">
            <label class="col-sm-2 control-label">任务名称：</label>
            <div class="col-sm-9">
                <input class="form-control" type="text" name="missionTitle" id="missionTitle" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label ">任务内容：</label>
            <div class="col-sm-9">
                <input class="form-control" type="text" name="missionText" id="missionText" required>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">部门：</label>
            <div class="col-sm-4">
                <select name="deptId"  class="form-control" id="deptId">
                    <option>请选择部门</option>
                    <option th:each="dept : ${personDepts}" th:value="${dept.deptId}" th:text="${dept.deptName}"></option>
                </select>
            </div>

            <label class="col-sm-2 control-label">执行人员：</label>
            <div class="col-sm-4">
                <select name="infoId"  class="form-control" id="infoId">
                    <option>请选择执行人</option>
                    <option value="-1">无</option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">结束时间：</label>
            <div class="col-sm-9">
                <input type="datetime-local" class="form-control" name="endTime" id="endTime" step="1">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label">任务状态：</label>
            <div class="col-sm-9">
                <select class="form-control" name="status">
                    <option value="1">已成功</option>
                    <option value="0">未成功</option>
                    <option value="2">放弃</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">紧急程度：</label>
            <div class="col-sm-9">
                <select class="form-control" name="urgencyLevel">
                    <option value="1">紧急</option>
                    <option value="0">一般</option>
                    <option value="2">非常紧急</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">备注：</label>
            <div class="col-sm-9">
                <textarea id="remark" name="remark" class="form-control"></textarea>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">

    $(function () {
        $("#deptId").change(function () {
            var deptId = $("#deptId").val();
            console.log(deptId);
            $.post(
                '/task/mission/selectPersomInfo',
                {
                    deptId:deptId
                },
                function(data){
                    console.log(data);
                    if(data != null){
                        $("#infoId").empty();
                        for(var i = 0 ; i < data.length ; i++){
                            $("#infoId").append("<option value='" + data[i].infoId + "'>" + data[i].infoName + "</option>");
                        }
                    }
                },"json"
            )
        });
    });

    var prefix = ctx + "task/mission";

    $("#form-mission-add").validate({
        onkeyup: false,
        rules:{
            missionTitle:{
                remote: {
                    url: ctx + "task/mission/checkMissionTitleUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "missionTitle" : function() {
                            return $.common.trim($("#missionTitle").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            infoName:{
                remote: {
                    url: ctx + "task/mission/checkInfoNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "infoName" : function() {
                            return $.common.trim($("#infoName").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "missionTitle": {
                remote: "任务标题已经存在"
            },
            "infoName": {
                remote: "当前执行人员不存在"
            }
        },
        focusCleanup: true
    });


    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-mission-add').serialize());
        }
    }
</script>
</body>
</html>
